#ifndef frmTest_control_TPageControl_H
#define frmTest_control_TPageControl_H

#include "svl_TWindow.h"
#include "frm_control_TPageControl.h"
#include "frm_control_TPanelWin.h"
#include "frm_control_TSplitter.h"
#include "frm_control_TFrame.h"
#include "frm_control_TParaEdit.h"
#include "frm_filler_TNodeSolidLine.h"
#include "frm_TMenu.h"

namespace frmTest_control_TPageControl {
  using namespace frm;

///////////////////////////////////////////////////////////////////////////////

struct TControlEdit : public frm::control::TPanelWin
{
  svl::TControlEdit Edit;
  //
  TControlEdit(frm::control::TWindow &Parent) : frm::control::TPanelWin(Parent),Edit(*this)
  {
  }
  virtual void TPanelWin_SetWindowRect(grf::TRect Rect)
  {
    Edit.MoveWindow(Rect.Left,Rect.Top,Rect.Width,Rect.Height,true);
  }
};

///////////////////////////////////////////////////////////////////////////////

struct TStyles
{
  TTableOfStyles S1,S2,S3;
  //
  TStyles()
  {
    {// S1 /////////////////////////////////////////////////////////
    static frm::control::TPanel::TStyle Panel; S1.Add(&Panel,false);
      Panel.Filler.Set(filler::TArray()
        .Add(filler::TColor(0,0,255))
        //.Add(filler::TFrameRect(0,0,0))
      );
      Panel.Cursor.Set(cursor::TCursorWin(IDC_ARROW));

    static frm::control::TString::TStyle String; S1.Add(&String,false);
      String.SetFontDefault();
      String.Normal.Font.Height.SetValue(20);
      String.CalcFontAll();

    static frm::control::TButton::TStyle Button; S1.Add(&Button,false);
      //Button.Normal.Filler.Set(filler::TColor(200,200,200));
      //Button.Flat.Filler.Set(filler::TFrameRect(0,0,0));
      //Button.Flat.Filler.Set(filler::TColor(200,200,200));
      Button.Down.Filler.Set(filler::TColor(128,128,128));

    static frm::control::TSplitterVert::TStyle SplitterVert; S1.Add(&SplitterVert,false);
      SplitterVert.Down.Filler.Set(filler::TFrameRect(0,255,255));

    static frm::control::TWindowClient::TStyle WindowClient; S1.Add(&WindowClient,false);
      WindowClient.Border.Set(10,10,10,10);
      WindowClient.Filler.Set(filler::TColor(150,150,150));

    // Page ///////////////////////////////////////////////////////////////////////
    static frm::control::TPageButton::TStyle PageButton; S1.Add(&PageButton,false);
      PageButton.Normal.Filler.Set(filler::TColor(255,255,255));
      PageButton.Down.Filler.Set(filler::TColor(128,128,128));
      PageButton.Normal.Border.Set(5,5,5,5);
      PageButton.Down  .Border.Set(5,5,5,5);
      PageButton.Flat  .Border.Set(5,5,5,5);
/******
    static frm::control::TPageString::TStyle PageString; S1.Add(&PageString,false);
      PageString.Normal.Cursor.Set(cursor::TCursorWin(IDC_ARROW));
      PageString.Focused.Cursor.Set(cursor::TCursorWin(IDC_CROSS));
*******/
    static frm::control::TPageControlButtons::TStyle PageControlButtons; S1.Add(&PageControlButtons,false);
      PageControlButtons.Filler.Set(filler::TArray()
        .Add(filler::TColor(255,255,255))
        .Add(filler::TFrameRect(255,0,0))
      );
      PageControlButtons.Border.Set(1,1,1,1);

    static frm::control::TPageControlClient::TStyle PageControlClient; S1.Add(&PageControlClient,false);
      PageControlClient.Filler.Set(filler::TArray()
        .Add(filler::TColor(0,0,255))
        .Add(filler::TFrameRect(200,0,0))
      );
      PageControlClient.Border.Set(10,10,10,10);

    static frm::control::TPage::TStyle Page; S1.Add(&Page,false);
      Page.Filler.Set(filler::TArray()
        .Add(filler::TColor(0,0,200))
        //.Add(filler::TFrameRect(0,200,0))
      );
 
    // ScrollBar ///////////////////////////////////////////////////////////////
/**********    
    static frm::control::TScrollBar::TStyle ScrollBar;
    S1.Add(&ScrollBar,false);
      ScrollBar.Filler.Set(filler::TColor(0,150,0));
      //ScrollBar.Border.Set(3,3,3,3);
*************/

    static frm::control::TScrollBarVertBegButton::TStyle ScrollBarVertBegButton;
    S1.Add(&ScrollBarVertBegButton,false);
      ScrollBarVertBegButton.SetDefault();
    static frm::control::TScrollBarVertEndButton::TStyle ScrollBarVertEndButton;
    S1.Add(&ScrollBarVertEndButton,false);
      ScrollBarVertEndButton.SetDefault();
    static frm::control::TScrollBarHorzBegButton::TStyle ScrollBarHorzBegButton;
    S1.Add(&ScrollBarHorzBegButton,false);
      ScrollBarHorzBegButton.SetDefault();
    static frm::control::TScrollBarHorzEndButton::TStyle ScrollBarHorzEndButton;
    S1.Add(&ScrollBarHorzEndButton,false);
      ScrollBarHorzEndButton.SetDefault();

    static frm::control::TScrollBarVertBegPage::TStyle ScrollBarVertBegPage;
    S1.Add(&ScrollBarVertBegPage,false);
      //ScrollBarVertBegPage.SetDefault();
    static frm::control::TScrollBarVertEndPage::TStyle ScrollBarVertEndPage;
    S1.Add(&ScrollBarVertEndPage,false);
      ScrollBarVertEndPage.SetDefault();
    static frm::control::TScrollBarHorzBegPage::TStyle ScrollBarHorzBegPage;
    S1.Add(&ScrollBarHorzBegPage,false);
      ScrollBarHorzBegPage.SetDefault();
    static frm::control::TScrollBarHorzEndPage::TStyle ScrollBarHorzEndPage;
    S1.Add(&ScrollBarHorzEndPage,false);
      ScrollBarHorzEndPage.SetDefault();

    static frm::control::TScrollBarVertTrack::TStyle ScrollBarVertTrack;
    S1.Add(&ScrollBarVertTrack,false);
      ScrollBarVertTrack.SetDefault();
      //ScrollBarVertTrack.Normal.Filler.Set(filler::TArray()
      //  .Add(filler::TColor(0,0,200))
      //  .Add(filler::TFrameRect(0,200,0))
      //);
    static frm::control::TScrollBarHorzTrack::TStyle ScrollBarHorzTrack;
    S1.Add(&ScrollBarHorzTrack,false);
      ScrollBarHorzTrack.SetDefault();
      //ScrollBarHorzTrack.Normal.Filler.Set(filler::TArray()
      //  .Add(filler::TColor(0,0,200))
      //  .Add(filler::TFrameRect(0,255,0))
      //);

    // Frame ////////////////////////////////
    static frm::control::TFrame::TStyle Frame;
    S1.Add(&Frame,false);
      Frame.Filler.Set(filler::TArray()
        .Add(filler::TColor(128,128,128))
        //.Add(filler::TFrameRect(0,0,0))
      );
      Frame.Border.Set(5,5,5,5);
    static frm::control::TFrameClient::TStyle FrameClient;
    S1.Add(&FrameClient,false);
      FrameClient.Filler.Set(filler::TColor(0,150,0));
      //FrameClient.Border.Set(10,10,10,10);
    static frm::control::TFramePanelScroll::TStyle FramePanelScroll;
    S1.Add(&FramePanelScroll,false);
      FramePanelScroll.Filler.Set(filler::TColor(255,255,255));

    // Line ////////////////////////////////
    static frm::control::TLine::TStyle Line;
    S1.Add(&Line,false);
      Line.Normal  .Border.Set(5,5,5,5);
      Line.Selected.Border.Set(5,5,5,5);
      Line.Focused .Border.Set(5,5,5,5);
      Line.Normal.Filler.Set(filler::TColor(255,255,255));
      Line.Selected.Filler.Set(filler::TColor(128,128,128));
      Line.Focused.Filler.Set(filler::TColor(200,0,0));

    // Row //////////////////////////////////////////////////////////
    frm::control::TRow::TStyle *Row = new frm::control::TRow::TStyle;
    S1.Add(Row,true);
      Row->Normal.Filler.Set(filler::TColor(200,200,200));
    frm::control::TRowCaption::TStyle *RowCaption = new frm::control::TRowCaption::TStyle;
    S1.Add(RowCaption,true);
      RowCaption->Normal  .Border.Set(0,0,0,1);
      RowCaption->Selected.Border.Set(0,0,0,1);
      RowCaption->Focused .Border.Set(0,0,0,1);
      RowCaption->Normal.Filler.Set(filler::TLineHorzBottom(0,0,0));
      RowCaption->Focused.Filler.Set(filler::TLineHorzBottom(0,0,0));
      RowCaption->Selected.Filler.Set(filler::TLineHorzBottom(0,0,0));
    static frm::control::TRowChildren::TStyle RowChildren;
    S1.Add(&RowChildren,false);
      RowChildren.Filler.Set(filler::TColor(200,200,200));
    static frm::control::TRowChildrenIndent::TStyle RowChildrenIndent;
    S1.Add(&RowChildrenIndent,false);
      RowChildrenIndent.Filler.Set(filler::TNodeSolidLine(grf::TColor(255,0,0)));

    frm::control::TRowExpand::TStyle *RowExpand = new frm::control::TRowExpand::TStyle;
    S1.Add(RowExpand,true);
      RowExpand->NoneChildren.Filler.Set(filler::TArray()
       .Add(filler::TRoundRect(grf::TColor(255,255,255),grf::TColor(0,0,193)))
      );
      RowExpand->Expand.Filler.Set(filler::TArray()
       .Add(filler::TRoundRect(grf::TColor(255,255,255),grf::TColor(0,0,193)))
       .Add(filler::TLineHorzCenter(255,255,255))
      );
      RowExpand->Collapse.Filler.Set(filler::TArray()
       .Add(filler::TRoundRect(grf::TColor(255,255,255),grf::TColor(0,0,193)))
       .Add(filler::TLineVertCenter(255,255,255))
       .Add(filler::TLineHorzCenter(255,255,255))
      );

    // Col ///////////////////////////////
    static frm::control::TCol::TStyle Col;
    S1.Add(&Col,false);
      Col.Normal  .Border.Set(1,1,1,0);
      Col.Selected.Border.Set(1,1,1,0);
      Col.Focused .Border.Set(1,1,1,0);
      //Col.Normal.Filler.SetNull();//(filler::TColor(255,255,255));
      Col.Selected.Filler.Set(filler::TColor(128,128,128));
      Col.Focused.Filler.Set(filler::TColor(200,0,0));

    // Para ////////////////////////////////////////////////////////////
    frm::control::TPara::TStyle *Para = new frm::control::TPara::TStyle;
    S1.Add(Para,true);
      //Col.Normal.Border = Col.Selected.Border = Col.Focused.Border.Set(1,1,1,0);
      Para->Normal.Filler.SetNull();//(filler::TColor(255,255,255));
      Para->Selected.Filler.Set(filler::TColor(128,128,128));
      Para->Focused.Filler.Set(filler::TColor(200,0,0));

    }//////////////////////////////////////////////////////////
  
    {// S2 /////////////////////////////////////////////////////////
    static frm::control::TPanel::TStyle Panel; S2.Add(&Panel,false);
      Panel.Filler.Set(filler::TArray()
        .Add(filler::TColor(240,240,240))
        //.Add(filler::TFrameRect(0,0,0))
      );
      Panel.Border.Set(10,10,10,10);
    }//////////////////////////////////////////

    {// S3 /////////////////////////////////////////////////////////
    static frm::control::TPanel::TStyle Panel; S3.Add(&Panel,false);
      //Panel.Filler.Set(filler::TArray()
      //  .Add(filler::TColor(0,0,255))
      //  .Add(filler::TFrameRect(0,0,0))
      //);
      //Panel.Cursor.Set(cursor::TCursorWin(IDC_ARROW));

    static frm::control::TPage::TStyle Page; S3.Add(&Page,false);
      Page.Filler.Set(filler::TArray()
        .Add(filler::TColor(255,255,255))
        //.Add(filler::TFrameRect(0,200,0))
      );
    }/////////////////////////////////

    
/**************
/////////////////////////////////////////////
    StyleW.Filler.Set(filler::TArray()
      .Add(filler::TColor(255,255,255))
      .Add(filler::TLineVertCenter(192,192,192))
      .Add(filler::TLineHorzCenter(192,192,192))
    );
    StyleW.Cursor.Set(cursor::TCursorWin(IDC_CROSS));

    Style1.Filler.Set(filler::TColor(0,0,255));
    Style1.Cursor.Set(cursor::TCursorWin(IDC_ARROW));

    Style2.Filler.Set(filler::TColor(0,255,0));
    Style2.Cursor.Set(cursor::TCursorWin(IDC_ARROW));
*******************/    
  }
};

///////////////////////////////////////////////////////////////////////////////

struct TForm : public frm::control::TPanel
{
  TStyles &Styles;
  //
  frm::control::TPageControl *Pages;
  frm::control::TPage *Page1,*Page2,*Page3;
  TControlEdit *Edit1,*Edit2;
  frm::TMainMenu MainMenu1,MainMenu2;
  //
  TForm(TStyles &Styles,frm::control::TWindow &Window);
  //
  control::TRow *AddRow(control::TPanel *Parent,svl::TString C1,svl::TString C2,svl::TString C3,svl::TString C4);
};

///////////////////////////////////////////////////////////////////////////////

struct TPageEvents : public frm::control::TPanel::TEvents
{
  TForm &Form;
  //
  TPageEvents(TForm &form) : Form(form) 
  {
    Form.Page1->Events.Link(*this);
    Form.Page2->Events.Link(*this);
  }
  //
  virtual void TEvents_BeforeChangeVisible(TChangeVisible &Param);
  virtual void TEvents_AfterChangeVisible (TChangeVisible &Param);
};
  
///////////////////////////////////////////////////////////////////////////////

struct TPageControlEvents : public frm::control::TPageControl::TEvents
{
  TForm &Form;
  //
  TPageControlEvents(TForm &form) : Form(form)
  {
    Form.Pages->Events.Link(*this);
  }  
  //
  virtual void TEvents_BeforeShowPage(TShowPage &Param);
  virtual void TEvents_AfterShowPage (TShowPage &Param);
};
  
///////////////////////////////////////////////////////////////////////////////

struct TWindowEvents : public frm::control::TWindow::TEvents
{
  TForm &Form;
  //
  TWindowEvents(TForm &form) : Form(form)
  {
    Form.GetWindow().Events.Link(*this);
  }  
  //
  virtual void TEvents_BeforeClose(TClose &Param);
};
  
///////////////////////////////////////////////////////////////////////////////

struct TCmdSetFocus : public svl::TCommand
{
  TForm &Form;
  //
  TCmdSetFocus(TForm &form) : Form(form) { n = 0; Caption = "TCmdSetFocus"; }
  //
  virtual void TCommand_Execute() 
  { 
    if (n == 0) { 
      Form.Edit1->Edit.SetFocus();
      n = 1;
    }
    else { 
      Form.Edit2->Edit.SetFocus();
      n = 0;
    }
    //::MessageBeep(0); }//svl::TMessageModal("TCommand1"); 
  }
  int n;
};
struct TCmd1 : public svl::TCommand
{
  TCmd1() { Caption = "TCmd1"; }
  virtual bool TCommand_GetEnable() 
  { 
/*********
    svl::TMessage::AddLine(
      "TCmd1:Enable"
    );
***********/
    //::MessageBeep(0); 
    return false;
  }
  virtual void TCommand_Execute() { ::MessageBeep(0); }//svl::TMessageModal("TCommand1"); }
};
struct TCmd2 : public svl::TCommand
{
  TCmd2() { Caption = "TCmd2"; }
  virtual void TCommand_Execute() { ::MessageBeep(0); }//svl::TMessageModal("TCommand1"); }
};
struct TCmd3 : public svl::TCommand
{
  TCmd3() { Caption = "TCmd3"; }
  virtual bool TCommand_GetEnable() { return false;}
  virtual void TCommand_Execute() { ::MessageBeep(0); }//svl::TMessageModal("TCommand1"); }
};

///////////////////////////////////////////////////////////////////////////////
void Test();
///////////////////////////////////////////////////////////////////////////////
}

#endif
